#pragma unmanaged

#include <BWSAL\InformationManager.h>
#include <BWSAL\BorderManager.h>

#pragma managed

#include "BaseManager.h"

#include "BorderManager.h"

#include "..\Util.h"

namespace BroodWar
{
	namespace Addon
	{
		BaseManager::BaseManager(BWSAL::BaseManager* manager)
		{
			instance = manager;
		}

		BaseManager::~BaseManager()
		{
			BWSAL::BaseManager::destroy();
		}

		BaseManager::!BaseManager()
		{
			BWSAL::BaseManager::destroy();
		}

		void BaseManager::Create(IBorderManager^ borderManager)
		{
			BorderManager^ manager = DirectCast<BorderManager^>(borderManager);
			BWSAL::BaseManager::destroy();
			s_instance = gcnew BaseManager(BWSAL::BaseManager::create(manager->instance));
		}

		BaseManager^ BaseManager::Instance::get()
		{
			return s_instance;
		}

		void BaseManager::OnFrame()
		{
			instance->onFrame();
		}
		
		void BaseManager::OnUnitDestroy(Unit^ unit)
		{
			instance->onUnitDestroy(ConvertUnit(unit));
		}
		
		Base^ BaseManager::GetBase(BaseLocation^ location)
		{
			return ConvertBase(instance->getBase(ConvertBaseLocation(location)));
		}

		Base^ BaseManager::ExpandNow()
		{
			return ConvertBase(instance->expandNow());
		}
		
		Base^ BaseManager::ExpandNow(BaseLocation^ location)
		{
			return ConvertBase(instance->expandNow(ConvertBaseLocation(location)));
		}
		
		Base^ BaseManager::ExpandNow(BaseLocation^ location, bool getGas)
		{
			return ConvertBase(instance->expandNow(ConvertBaseLocation(location), getGas));
		}
		
		Base^ BaseManager::ExpandWhenPossible()
		{
			return ConvertBase(instance->expandWhenPossible());
		}
		
		Base^ BaseManager::ExpandWhenPossible(BaseLocation^ location)
		{
			return ConvertBase(instance->expandWhenPossible(ConvertBaseLocation(location)));
		}
		
		Base^ BaseManager::ExpandWhenPossible(BaseLocation^ location, bool getGas)
		{
			return ConvertBase(instance->expandWhenPossible(ConvertBaseLocation(location), getGas));
		}
		
		Base^ BaseManager::ExpandAtFrame(int frame)
		{
			return ConvertBase(instance->expandAtFrame(frame));
		}
		
		Base^ BaseManager::ExpandAtFrame(int frame, BaseLocation^ location)
		{
			return ConvertBase(instance->expandAtFrame(frame, ConvertBaseLocation(location)));
		}
		
		Base^ BaseManager::ExpandAtFrame(int frame, BaseLocation^ location, bool getGas)
		{
			return ConvertBase(instance->expandAtFrame(frame, ConvertBaseLocation(location), getGas));
		}

		HashSet<Base^>^ BaseManager::ActiveBases::get()
		{
			return ToHashSet<BWSAL::Base*, Base^>(instance->getActiveBases(), &ConvertBase);
		}

		HashSet<Base^>^ BaseManager::ReadyBases::get()
		{
			return ToHashSet<BWSAL::Base*, Base^>(instance->getReadyBases(), &ConvertBase);
		}
		
		HashSet<Base^>^ BaseManager::AllBases::get()
		{
			return ToHashSet<BWSAL::Base*, Base^>(instance->getAllBases(), &ConvertBase);
		}
		
		HashSet<Base^>^ BaseManager::DestroyedBases::get()
		{
			return ToHashSet<BWSAL::Base*, Base^>(instance->getDestroyedBases(), &ConvertBase);
		}

		String^ BaseManager::Name::get()
		{
			return gcnew String(instance->getName().c_str());
		}

		String^ BaseManager::ToString()
		{
			return Name;
		}
	}
}
